<template>
	<view class="contaner">
		<view class="content" @click="getjin">
			<view class="item" v-html="parame.content"></view>
			<view class="item" style="height: 180rpx; line-height: 70rpx;">
				<text class="first-text">报名进度：</text>
				<text class="two-text">医生：{{parame.countDoctor}} / ({{parame.minDoctor}})</text>
				<text>总人数：{{parame.countApply}} / {{parame.maxApply}}</text>
				<view style="font-size: 28rpx; color: #C0C0C0;">括号里为最少医生数量</view>
			</view>
		</view>
		<view class="footer" :class="{footer1: show}">
			<van-button round block color='#02BF88' @click="getApply">{{ btext }}</van-button>
		</view>
		<van-toast id='van-toast'/>
	</view>
</template>

<script>
import {appraisingList, addapplyUser, getIsTrue} from '@/api/appraising.js'	
	export default {
		data() {
			return {
				show: false,
				btext: '立即报名',
				id: undefined,
				parame: {
					countDoctor: 0,
					minDoctor: 0,
					maxApply: 0,
					countApply: 0
				}
			}
		},
		onLoad(data) {
			if (data!== null) {
				this.id = data.id
				this.getzt()
			}
		},
		methods:{
			onShow() {
				var rz = JSON.parse(uni.getStorageSync('roleDataInfo'))
				if (rz.type === 1) {
				uni.showModal({
				    title: '提示',
				    content: '您还未认证，是否去认证？',
					confirmColor: '#02BF88',
					cancelColor: '#323233',
				    success: function (res) {
				        if (res.confirm) {
				             uni.navigateTo({
				                     url: '/pages/personal/authentication',
				              });
				        } else if (res.cancel) {
				            uni.navigateBack({
				            delta: 1
				            })
				        }
				    }
				});
			}
			},
			getjin() {
				this.getIstrue()
			},
			getIstrue() {
				getIsTrue({meetingId: this.parame.id}).then(res => {
					if (res.data) {
						uni.navigateTo({
						        url: '/packageA/pages/applyList/setapply?data=' + JSON.stringify(this.parame),
						 });
					}
				})
			},
			getzt() {
				const id = this.id
				appraisingList({id}).then(res => {			 
					this.parame = res.data
					this.getIstrue()
					if (this.parame.countApply === this.parame.maxApply) {
						this.btext = '已报满'
						this.show = true
					}
				})
			},
			getApply() {
				if (this.btext === '已报满') {
					return
				}
				const parame = {
					meetingId: this.parame.id,
					userId: this.$storage.getItem('userInfo').user.userId
				}
				addapplyUser({...parame}).then(res => {
					if (res.status === 1) {
						this.$toast.success(res.message)
						this.parame.countApply ++
						uni.navigateTo({
						        url: '/packageA/pages/applyList/setapply?data=' + JSON.stringify(this.parame),
						 });
					} else {
						this.$toast.fail(res.message)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.contaner {
		height: 100vh;
		background-color: #F8F8F8;
		.content {
			padding: 24rpx 32rpx 0;
			.item {
				background-color: #FFFFFF;
				position: relative;
				width: 100%;
				border-radius: 10rpx;
				padding: 38rpx 16rpx;
				color: #323233;
				font-size: 32rpx;
				line-height: 44rpx;
				box-sizing: border-box;
				.first-text {
					color: #666666;
					font-size: 28rpx;
				}
				.two-text {
					color: #333333;
					margin-right: 24rpx;
				}
			}
		}
		.footer {
			position: fixed;
			padding: 24rpx 32rpx;
			box-sizing: border-box;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 132rpx;
			z-index: 999;
			background-color: #FFFFFF;
		}
	}
	.footer1 /deep/ .van-button--round {
		opacity: 0.3;
	}
	
</style>
